package com.luying.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.luying.dao.StudentMoralScoreDao;
import com.luying.dao.StudentScoreDao;
import com.luying.dao.TeacherDao;
import com.luying.pojo.*;
import com.luying.pojo.Class;
import com.luying.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TeacherServiceImpl implements TeacherService{
    @Autowired
    private TeacherDao teacherDao;
    @Autowired
    private StudentScoreDao studentScoreDao;
    @Autowired
    private StudentMoralScoreDao studentMoralScoreDao;

    @Override
    public Map<String, Object> getAllScreen(Integer id) {
        Map<String,Object> resp = new HashMap<>(16);
        //根据id 获取该教师所有负责的所有的班级
        List<BaseDown> classes = teacherDao.selectAllClass(id);
        //根据id 获取该教师所有负责的所有科目
        List<BaseDown> subjects = teacherDao.selectAllSubject(id);
        resp.put("classes",classes);
        resp.put("subjects",subjects);
        return resp;
    }

    @Override
    public void addScore(StudentScore studentScore) {
        studentScoreDao.insertSelective(studentScore);
    }

    @Override
    public List<Class> teacherClass(Integer id) {
        //根据id 获取该教师所有负责的所有的班级
        List<Class> classes = teacherDao.teacherClass(id);
        return classes;
    }

    @Override
    public Map<String, Object> subjectAndStudent(Integer teacherId, Integer classId) {
        Map<String,Object> resp = new HashMap<>(16);
        //查询该老师负责的该班级的课程
        List<BaseDown> subjects = teacherDao.subjectClass(teacherId,classId);
        resp.put("subjects",subjects);
        //查询该班级的学生
        List<BaseDown> students = teacherDao.selectAllStudents(classId);
        resp.put("students",students);
        return resp;
    }

    @Override
    public PageResult scoreList(ScorePageQuery pageQuery) {
        PageHelper.startPage(pageQuery.getPageIndex(),pageQuery.getPageSize());
        List<ScoreList> list = teacherDao.selectScoreList(pageQuery);
        PageInfo<ScoreList> pageInfo = new PageInfo(list);
        PageResult pageResult = new PageResult(pageInfo.getTotal(),list);
        return pageResult;
    }

    @Override
    public List<BaseDown> year() {
        return teacherDao.selectAllYear();
    }

    @Override
    public List<BaseDown> moralScreen() {
        List<BaseDown> list = teacherDao.selectAllMoral();
        return list;
    }

    @Override
    public Object moralAdd(StudentMoralScore studentMoralScore) {
        return studentMoralScoreDao.insertSelective(studentMoralScore);
    }

    @Override
    public PageResult moralList(ScorePageQuery pageQuery) {
        PageHelper.startPage(pageQuery.getPageIndex(),pageQuery.getPageSize());
        List<ScoreList> list = teacherDao.selectMoralScoreList(pageQuery);
        PageInfo<ScoreList> pageInfo = new PageInfo(list);
        PageResult pageResult = new PageResult(pageInfo.getTotal(),list);
        return pageResult;
    }
}
